package com.suozq.springcloud.order.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfig {
    
	@Bean
	@LoadBalanced
	public RestTemplate restTemplate() {
	        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
	        requestFactory.setConnectTimeout(30000);// 设置连接超时，单位毫秒
	        requestFactory.setReadTimeout(30000);  //设置读取超时
	        RestTemplate restTemplate = new RestTemplate();
	        restTemplate.setRequestFactory(requestFactory);
	        return restTemplate;
	}
}
